package openadmin.model.control;

/**
 * <desc>class that stores the basic information between action and role</desc>
 * <responsibility>Represents all the actions that have the role</responsibility>
 * <coperation>Interface Base</coperation>
 * @version  0.1
 * Created 10-05-2008
 * Modifier 15-04-2009 
 * Author Alfred Oliver
*/

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import openadmin.dao.Base;


@Entity
@Table(name = "actionrole", schema = "control")
public class ActionRole implements Base, java.io.Serializable {

	/** attribute that contains the identifier*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	private Integer id;
	
	/** Field that contains the description*/	
	@Column(unique = true)
	@Length(max = 50)
	private String description;	
	

	/** Transient attribute that means that the system should make a log on any JPA operation of this class*/
	@Transient 
	private boolean debuglog = true;
	
	/** Transient attribute that means that the system should make a historic on any JPA operation of this class*/
	@Transient
	boolean historiclog = false;
	
	/** attribute that contains the relationship with role*/
	@ManyToOne
	@JoinColumn(name = "role", nullable= false)
	private Role role;
	
	/** attribute that contains the relationship with action*/
	@ManyToOne
	@JoinColumn(name = "action", nullable= false)
	private Action action;

	/**
	 * Constructor of the class ActionRole.
	 * without parameters
	 */
	public ActionRole() {

	}

	/**
	 * Constructor of the class ActionRole.
	 * @param pDescription, is the description, (unique value), of the ActionRole
	 */
	public ActionRole(String pDescription) {
		
		this.description = pDescription.toLowerCase();
	}
	
	/** Getters and setters*/	
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer pId) {
		this.id = pId;
	}
	
	/**
	 * <desc> Accessor of reading which gives us the description, unique value</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the return is the description of x </post>
	 * @return description of object
	 */	
	public String getDescription() {
		return this.description;
	}

	/**
	 * <desc> Accessor of writing which gives us the description</desc>
	 * <pre> x is an instance of ActionClass</pre>
	 * <post> the description is stored</post>
	 * @param pDescription, description of object, unique value
	 */	
	public void setDescription(String pDescription) {
		this.description = pDescription.toLowerCase();		
	}
	
	public boolean getDebugLog() {
		return debuglog;
	}
	
	public void setDebugLog(boolean pDebuglog) {
		debuglog = pDebuglog;
	}
	
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role pRole) {
		this.role = pRole;
	}
	
	public Action getAction() {
		return this.action;
	}

	public void setAction(Action pAction) {
		this.action = pAction;
	}

	public boolean getHistoricLog() {
		return historiclog;
	}

	public void setHistoricLog(boolean historiclog) {
		this.historiclog = historiclog;
	}
	
	@Override
	public String toString(){
	      
		return description;
	
	}
}
